package com.soccer.soccerclub.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.soccer.soccerclub.entity.PlayingField;
import com.soccer.soccerclub.service.PlayingFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-19
 */
@RestController
@RequestMapping("/playing")
public class PlayingFieldController {
    @Autowired
    private PlayingFieldService playingFieldService;

    /**
     * 前台区域列表
     * @return
     */
    @GetMapping("/listPlay")
    public R listPlay(){
        List<PlayingField> list = playingFieldService.list(new LambdaQueryWrapper<PlayingField>().ne(PlayingField::getAreaType, 8).eq(PlayingField::getStatus, 0));
        return R.ok(list);
    }

    /**
     * 后台区域列表
     * @return
     */
    @GetMapping("/list")
    public R list(Page<PlayingField> page){
        Page<PlayingField> list = playingFieldService.page(page);
        return R.ok(list);
    }

    /**
     * 修改区域状态
     * @param id 区域id
     * @param status 状态 0启用 1禁用
     * @return
     */
    @GetMapping("/updateStatus")
    public R updateStatus(Integer id ,Integer status){
        PlayingField playingField = playingFieldService.getById(id);
        playingField.setStatus(status);
        boolean update = playingFieldService.updateById(playingField);
        return R.ok(update);
    }
}

